<?php

/**
*控制基类
*/
class Controller extends Smarty
{
	public function __construct()
	{
		//配置smarty 对象链方式
		$this->setTemplateDir('./views')
		       ->setCompileDir('./run_time/views_c')
		       ->setConfigDir('./configs')
		       ->setCacheDir('./run_time/caches');

		//配置模板变量定界符
		$this->left_delimiter = "<{";
		$this->right_delimiter = "}>";

		//配置缓存
		$this->caching = false;//开启缓存
		$this->cache_lifetime = 30; //缓存

	}

	public function __call($fun, $params)
	{
		header("HTTP/1.0 404 not found");
        header("Status: 404 not found");//兼容IE
        echo "<h1>404 NOT FOUND 方法不存在</h1>";
        exit();
	}

	public function redirect($message, $url=null)
	{
		echo "<script>alert('{$message}')</script>";
		if (empty($url)) {
			//未传递url参数 则回到来之前的页面
			echo "<script>history.back()</script>";
		} else {
			//跳转到指定页面
			echo "<script>location.href='{$url}'</script>";
		}
	}
}